package es.ucm.is.www.GUI.client.city;

import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
/**
 * <p>Title: VillagerPopup.java </p>
 *
 * <p>Description: Panel emergente de los aldeanos</p>
 *
 * <p>Copyright: </p>
 *
 * @author Javier Pla Herrero
 * @author Fernando Burillo
 * @version 1.0
 * @see
 */
public class VillagerPopup extends Villager implements MouseListener{
	
	private PopupPanel panel;
	private boolean clicked;
	private int xActual;
	private int yActual;
	/**
	 * Contructora de la clase
	 * @param imag: imagen
	 * @param x: posicion x
	 * @param y: posicion y
	 */
	public VillagerPopup(AbstractImagePrototype img,int x, int y){
		super(img);
		clicked = false;
		panel = new PopupPanel();
		xActual = x;
		yActual = y;
		this.getImagen().addMouseListener(this);
		panel.setPopupPosition(x, y);
		panel.add(this);
		panel.show();
	}

	public void onMouseDown(Widget sender, int x, int y) {
		// TODO Auto-generated method stub
		clicked = true;
		xActual = x;
		yActual = y;
	}

	public void onMouseEnter(Widget sender) {
		// TODO Auto-generated method stub
		
	}

	public void onMouseLeave(Widget sender) {
		// TODO Auto-generated method stub
		clicked = false;
	}

	public void onMouseMove(Widget sender, int x, int y) {
		// TODO Auto-generated method stub
		int xDiff = x - xActual;
		int yDiff = y - yActual;
		
		if(clicked){
			panel.setPopupPosition(panel.getAbsoluteLeft() + xDiff, panel.getAbsoluteTop() + yDiff);
		}
	}

	public void onMouseUp(Widget sender, int x, int y) {
		// TODO Auto-generated method stub
		clicked = false;
	}
	
}
